package jmine.tec.hydra.receive.impl.file;

import java.io.File;
import java.io.FileFilter;

import jmine.tec.annotations.Unmodifiable;
import jmine.tec.hydra.util.monitor.DirectoryListener;

/**
 * AbstractFileFilter that only accepts files that exist and which suffix is not one of {@link DirectoryListener#PROCESSING},
 * {@link DirectoryListener#FALHA} or {@link DirectoryListener#SUCESSO}
 * <p>
 * Implementors must override {@link #doAcceptFile(File)}
 * 
 * @author takeshi
 */
@Unmodifiable
public abstract class AbstractHydraFileFilter implements FileFilter {

    /**
     * {@inheritDoc}
     */
    public final boolean accept(File file) {
        return file.isFile() && file.exists() && !file.getName().endsWith(DirectoryListener.PROCESSING)
                && !file.getName().endsWith(DirectoryListener.FALHA) && !file.getName().endsWith(DirectoryChangedListener.SUCESSO)
                && doAcceptFile(file);
    }

    /**
     * Implementors must override this method and implement the remaning logic
     * 
     * @param file the {@link File}
     * @return boolean
     */
    protected abstract boolean doAcceptFile(File file);

}
